/**
 * 不能编辑的用户组
 */
const CANT_EDIT_USERGROUP = ["演示账号", "市级账号", "省级账号"]

/**
 * 用户组是否存在不可编辑用户组
 * @param {*} userGroup
 */
function userGroupCanEdit(userGroup) {
  if (CANT_EDIT_USERGROUP.includes(userGroup)) return true
  return false
}

export const generateColumns = vm => {
  return [
    {
      title: "用户组",
      align: "center",
      key: "userGroup"
    },
    {
      title: "用户名",
      key: "userName",
      align: "center"
    },

    {
      title: "更新时间",
      key: "updatedAt",
      align: "center",
      render: (h, params) =>
        h("span", vm.moment(params.row.updatedAt).format("YYYY/MM/DD HH:mm:ss"))
    },
    {
      title: "操作",
      align: "center",
      width: 200,
      render: (h, params) => {
        return h("div", [
          userGroupCanEdit(params.row.userGroup)
            ? null
            : h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                    disabled:
                      vm.userRole === "ROLE_DEMO" ||
                      vm.userRole === "ROLE_CITY" ||
                      vm.userRole === "ROLE_PROVINCE"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      vm.handelEdit(params.row)
                    }
                  }
                },
                "编辑"
              ),
          h(
            "Button",
            {
              style: {
                marginRight: "5px"
              },
              props: {
                type: "warning",
                size: "small"
              },
              on: {
                click: () => {
                  vm.handelReset(params.row)
                }
              }
            },
            "重置密码"
          ),
          h(
            "Poptip",
            {
              props: {
                confirm: true,
                title: "您确定要删除这条数据吗?",
                transfer: true,
                cancelText: "取消"
              },
              on: {
                "on-ok": () => {
                  vm.handelDelete(params.row)
                }
              }
            },
            [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small",
                    disabled: vm.userRole === "ROLE_DEMO"
                  }
                },
                "删除"
              )
            ]
          )
        ])
      }
    }
  ]
}

export const buildTreeData = array => {
  return array.map(t => {
    return {
      label: t.name,
      id: t.id
    }
  })
}
